﻿layui.use(['element', "layer", "jquery"], function () {
    var $ = layui.jquery;
    var element = layui.element;
    var mainHeight = $(window).height() - 60 - 41 - 44 - 7;
    $("#HomePage").height(mainHeight);
    //监听Tab切换，以改变地址hash值
    element.on('nav(menulist)',
        function(elem) {
            var url = elem.find('a').attr('_href'),
                title = elem.find('cite').text(),
                tabid = elem.find('a').attr("id"),
                length = $(".layui-tab-title").children("li[lay-id='" + tabid + "']").length;
            if (!length) {
                LoadPage(element, tabid, url, mainHeight, title);
            } else {
                element.tabChange('x-tab', tabid);
            }
            $('.layui-tab-title li').eq(0).find('i').remove();
        });
});
function LoadPage(element, tabid, url, mainHeight,title) {
    var iframe = '<iframe frameborder="0" src="' + url +
        '" class="layui-iframe" style="height:' + mainHeight + 'px;"></iframe>';
    element.tabAdd('x-tab', { title: title, id: tabid, content: iframe });
    element.tabChange('x-tab', tabid);
}